package com.ruoyi.student.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import com.ruoyi.student.mapper.StudentMapper;
import com.ruoyi.student.domain.Student;
import com.ruoyi.student.service.IStudentService;

/**
 * 学生Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-11
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 查询学生列表
     *
     * @param student 学生
     * @return 学生
     */
    @Override
    public List<Student> selectStudentList(Student student)
    {
        List<Student> studentList = studentMapper.selectList(buildQueryWrapper(student));
        return studentList;
    }


    private LambdaQueryWrapper<Student> buildQueryWrapper(Student query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<Student> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getName()), Student::getName, query.getName());
        lqw.eq(query.getAge() != null, Student::getAge, query.getAge());
        lqw.eq(query.getSex() != null, Student::getSex, query.getSex());
        lqw.orderByDesc(Student::getCreateTime);
        return lqw;
    }

}
